package com.starling.view
{
	import com.bit101.components.CheckBox;
	import com.bit101.components.ComboBox;
	import com.bit101.components.InputText;
	import com.bit101.components.PushButton;
	import com.bit101.components.RadioButton;
	import com.bit101.components.Style;
	import com.bit101.components.TextArea;
	import com.bit101.utils.MinimalConfigurator;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.NativeDragEvent;
	import flash.filesystem.File;
	
	public class MainView extends Sprite
	{
		private var _config:MinimalConfigurator;
		
		public var button_file:PushButton;
		public var button_dir:PushButton;
		public var button_update:PushButton;
		public var button_publish:PushButton;
		public var button_open_dir:PushButton;
		public var button_debug:PushButton;
		public var button_jsfl_classLinkName:PushButton;
		
		public var box_view:ComboBox;
		public var check_match:CheckBox;
		
		public var text_file_info:TextArea;
		public var text_file_path:InputText;
		
		public var input_padding:InputText;
		public var input_width:InputText;
		public var input_height:InputText;
		public var input_scale:InputText;
		
		public function MainView()
		{
			super();
			
			//new CheckBox
			
			Style.fontName = "宋体";
			Style.embedFonts = false;
			Style.fontSize = 13;
			
			_config = new MinimalConfigurator(this);
			_config.loadXML("main.xml");
			_config.addEventListener(Event.COMPLETE,function():void{
				
				button_debug = _config["getCompById"]("button_debug");
				box_view = _config["getCompById"]("box_view");
				check_match = _config["getCompById"]("check_match");
				
				button_file = _config["getCompById"]("button_swf");
				button_dir = _config["getCompById"]("button_dir");
				button_update = _config["getCompById"]("button_update");
				button_publish = _config["getCompById"]("button_publish");
				button_open_dir = _config["getCompById"]("button_open_dir");
				button_jsfl_classLinkName = _config["getCompById"]("button_jsfl_classLinkName");
				
				text_file_path = _config["getCompById"]("text_file_path");
				text_file_info = _config["getCompById"]("text_file_info");
				
				input_padding = _config["getCompById"]("input_padding");
				input_width = _config["getCompById"]("input_width");
				input_height = _config["getCompById"]("input_height");
				input_scale = _config["getCompById"]("input_scale");
				
				input_width.addEventListener(Event.CHANGE ,inputChangeHandler);
				input_height.addEventListener(Event.CHANGE ,inputChangeHandler);
				input_padding.addEventListener(Event.CHANGE ,inputChangeHandler);
				input_scale.addEventListener(Event.CHANGE ,inputChangeHandler);
			});
			
		}
		
		
		
		/**
		 * 输入文本限制处理 
		 * @param event
		 * 
		 */		
		private function inputChangeHandler(event:Event):void
		{
			input_width.text = input_width.text.length<1?"0":String(Number(input_width.text));
			input_height.text = input_height.text.length<1?"0":String(Number(input_height.text));
			input_padding.text = input_padding.text.length<1?"0":String(Number(input_padding.text));
			//input_scale.text = input_scale.text.length<1?"0":String(Number(input_scale.text));
		}
		
		
		
		
		/**
		 * UI 点击事件 
		 * @param event
		 * 
		 */
		
		public function buttonClick(event:Event):void
		{
			switch(event.target.name)
			{
				case "button_file":					Manage.mainControl.select("file");		break;
				case "button_dir":						Manage.mainControl.select("dir");		break;
				case "button_update":					Manage.mainControl.onUpdate();			break;
				case "button_publish":				Manage.mainControl.onPublish();			break;
				case "button_open_dir":				Manage.mainControl.openDIR();			break;
				case "button_jsfl_classLinkName":	Manage.mainControl.onJSFL();			break;
				case "button_debug":															break;
			}
			
			//box_view.removeAll();
			//box_view.selectedIndex = -1;
		}
		
		
		
		/**
		 * comboBox 选择事件 
		 * @param event
		 * 
		 */		
		public function viewSelect(event:Event):void
		{
			
		}
		
		
		
		
		
	}
}